package com.joysuch.wwyt.datadump.biz.processor;

import cn.zlg.common.datadump.annotation.DataDumpEntity;
import cn.zlg.common.datadump.processor.BaseImportEntityProcessor;
import com.joysuch.wwyt.datadump.biz.model.MhChemProductDumpBean;
import com.joysuch.wwyt.datadump.biz.model.MhMonitorPointDumpBean;
import com.joysuch.wwyt.mh.entity.MhMajorHazardChemProduct;
import com.joysuch.wwyt.mh.entity.MhMonitoringPoint;
import com.joysuch.wwyt.mh.entity.MhMonitoringType;
import com.joysuch.wwyt.mh.repository.MhMajorHazardChemProductDao;
import com.joysuch.wwyt.mh.repository.MhMonitoringPointDao;
import com.joysuch.wwyt.mh.repository.MhMonitoringTypeDao;
import com.mysema.commons.lang.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Component
public class MhChemProductImportProcessor extends BaseImportEntityProcessor<MhChemProductDumpBean, MhMajorHazardChemProduct> {

    @Autowired
    private MhMajorHazardChemProductDao chemProductDao;

    /**
     * 保存后执行，确保新增、修改实体，entity都是持久化对象。
     * 如果是 processBeforeSave(), 创建的实体如果已经存在，将复制 DumpBean中importIgnore=false的属性，导致monitoringType属性丢失
     * @param origin
     * @param entity
     * @param annotation
     * @return
     */
    @Override
    public MhMajorHazardChemProduct processBeforePersist(MhChemProductDumpBean origin, MhMajorHazardChemProduct entity, DataDumpEntity annotation, boolean override) {
        Assert.isTrue(chemProductDao.countByCasNoAndCodeNotEq(origin.getCasNo(), origin.getCode()) == 0, "CAS号【"+origin.getCasNo()+"】已存在 ");
        return entity;
    }


}
